import Taro from '@tarojs/taro'
import app from '../../../main.js'
let myJs = {
    getData: function() {
        this.state = {
            doctor_id: '',
            patients: []
        };
        return this.state;
    },
    
    allPatients() {
        var me = this;
        app.get("api/case_details/getPatients", {id: app.current.id}, function(res) {
            me.setState({
                patients: res.data.result
            });
        });
    },

    gotoEditCase(id) {
        var me = this;
        var doctor_id = this.state.doctor_id ? this.state.doctor_id: app.current.id;
        var data = {id: id, doctor_id: doctor_id, type: this.$router.params.type};
        if (this.$router.params.project_id) {
            data.project_id = this.$router.params.project_id
        }

        app.post("api/case_details/createCaseFromPatient", data, function(res) {
            var id = res.data.result;
            me.redirectTo("../editCase/editCase?id="+id);
        });
    },
    
    componentWillMount () {
        this.init();
    },
    navigateTo(url) {
        app.navigateTo(url);
    },
    handleChange(name, v) {
        var names = name.split('.');
        var n = names[0];
        var temp = this.state;
        for(var i = 0; i < names.length - 1; i++) {
            temp = temp[names[i]];
        }
        
        if(names.length > 1) {
            temp[names[i]] = v;
            this.setState({n: temp});
        } else {
            this.setState({n: v});
        }
    },
    redirectTo(url) {
        app.redirectTo(url);
    },
    componentDidMount () {},
    componentWillUnmount () {},
    componentDidHide () {}
}
export default myJs;
